In [2]:
import csv

%matplotlib inline

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

READ


In [16]:
y_axis = []
x_axis = []
y_progress = 0

with open("encoder.csv", 'rb') as encoder_data:
    reader = csv.reader(encoder_data)
    count = 0
    for row in reader:
        if count % 2 == 1:
            fy = float(row[0])
            y_progress += (fy / 1000000.00)
            x_axis.append(y_progress)
            y_axis.append(fy)
            print fy
        count += 1

# Wheel Circm. == 114mm
# Gear Ratio == 150
# Counts == 12

event_distance_mm = (1 / (150.00 * 12.00)) * 114.00
y_axis = [event_distance_mm / (y_axis[t] / 1000000.00) for t in range(0, len(y_axis))]


17940595.0
2932.0
3109.0
1982.0
2110.0
1755.0
1822.0
1434.0
1943.0
1189.0
1627.0
1393.0
1519.0
1144.0
1547.0
1207.0
1383.0
1239.0
1348.0
1090.0
1540.0
970.0
1357.0
1177.0
1286.0
986.0
1349.0
1054.0
1215.0
1107.0
1203.0
998.0
1403.0
890.0
1259.0
1073.0
1200.0
918.0
1265.0
985.0
1155.0
1036.0
1154.0
951.0
1344.0
850.0
1207.0
1059.0
1172.0
905.0
1222.0
972.0
1126.0
1029.0
1123.0
928.0
1326.0
841.0
1210.0
1028.0
1152.0
885.0
1226.0
955.0
1121.0
1012.0
1128.0
926.0
1314.0
833.0
1191.0
1052.0
1136.0
886.0
1207.0
961.0
1105.0
1015.0
1116.0
929.0
1311.0
828.0
1170.0
1037.0
1141.0
886.0
1200.0
941.0
1106.0
1008.0
1109.0
914.0
1308.0
829.0
1189.0
1014.0
1139.0
880.0
1221.0
946.0
1103.0
8.0
2125.0
927.0
1324.0
831.0
1196.0
1037.0
1149.0
885.0
1214.0
959.0
1104.0
1010.0
1111.0
927.0
1312.0
828.0
1183.0
1037.0
1148.0
886.0
1204.0
958.0
1117.0
1022.0
1109.0
923.0
1313.0
836.0
1193.0
1025.0
1145.0
885.0
1223.0
942.0
1108.0
1013.0
1136.0
931.0
1327.0
835.0
1203.0
1051.0
1167.0
902.0
1231.0
973.0
1118.0
1030.0
1134.0
946.0
1343.0
848.0
1197.0
1048.0
1162.0
904.0
1236.0
951.0
1123.0
1021.0
1144.0
927.0
1335.0
842.0
1214.0
1055.0
1168.0
900.0
1236.0
977.0
1126.0
1030.0
1132.0
944.0
1339.0
845.0
1200.0
1055.0
1167.0
905.0
1233.0
955.0
1125.0
1028.0
1144.0
926.0
1332.0
843.0
1217.0
1053.0
1177.0
900.0
1236.0
976.0
1125.0
1033.0
1137.0
949.0
1339.0
840.0
1201.0
1048.0
1165.0
902.0
1225.0
957.0
1119.0
1021.0
1132.0
922.0
1328.0
842.0
1208.0
1039.0
1162.0
892.0
1231.0
966.0
1127.0
1014.0
1131.0
936.0
1325.0
844.0
1198.0
1052.0
1166.0
895.0
1224.0
971.0
1129.0
1035.0
1123.0
935.0
1330.0
847.0
1212.0
1035.0
1160.0
897.0
1233.0
962.0
1127.0
1023.0
1141.0
943.0
1336.0
847.0
1207.0
1058.0
1169.0
902.0
1236.0
977.0
1131.0
1036.0
1123.0
940.0
1335.0
850.0
1209.0
1032.0
1156.0
895.0
1238.0
963.0
1125.0
1024.0
1142.0
931.0
1330.0
844.0
1208.0
1058.0
1161.0
903.0
1226.0
977.0
1133.0
1039.0
1129.0
943.0
1336.0
850.0
1206.0
1043.0
1164.0
902.0
1244.0
958.0
1124.0
1028.0
1150.0
939.0
1340.0
847.0
1214.0
1062.0
1175.0
910.0
1241.0
983.0
1138.0
1044.0
1136.0
952.0
1349.0
857.0
1219.0
1041.0
1167.0
902.0
1247.0
970.0
1137.0
1032.0
1149.0
946.0
1346.0
858.0
1222.0
1067.0
1187.0
912.0
1250.0
993.0
1154.0
1055.0
1155.0
946.0
1358.0
860.0
1240.0
1067.0
1200.0
907.0
1252.0
988.0
1142.0
1046.0
1151.0
959.0
1356.0
856.0
1213.0
1071.0
1183.0
916.0
1253.0
963.0
1135.0
1035.0
1154.0
945.0
1351.0
845.0
1222.0
1066.0
1175.0
913.0
1243.0
982.0
1135.0
1038.0
1132.0
948.0
1339.0
854.0
1202.0
1039.0
1158.0
899.0
1241.0
957.0
1122.0
1024.0
1142.0
934.0
1336.0
841.0
1214.0
1060.0
1171.0
905.0
1234.0
977.0
1128.0
1040.0
1135.0
948.0
1339.0
853.0
1201.0
1048.0
1165.0
901.0
1244.0
952.0
1122.0
1025.0
1147.0
936.0
1335.0
839.0
1213.0
1052.0
1169.0
904.0
1235.0
979.0
1126.0
1032.0
1134.0
945.0
1341.0
849.0
1197.0
1049.0
1159.0
905.0
1239.0
954.0
1129.0
1025.0
1146.0
936.0
1342.0
845.0
1222.0
1065.0
1180.0
908.0
1239.0
985.0
1132.0
1044.0
1144.0
953.0
1349.0
858.0
1217.0
1053.0
1176.0
908.0
1256.0
966.0
1132.0
1037.0
1156.0
949.0
1350.0
858.0
1220.0
1075.0
1185.0
923.0
1256.0
995.0
1153.0
1053.0
1154.0
956.0
1363.0
866.0
1243.0
1066.0
1201.0
916.0
1264.0
998.0
1154.0
1054.0
1159.0
967.0
1370.0
869.0
1227.0
1077.0
1193.0
921.0
1274.0
984.0
1154.0
1054.0
1173.0
961.0
1367.0
867.0
1230.0
1089.0
1203.0
929.0
1258.0
998.0
1157.0
1058.0
1176.0
954.0
1370.0
864.0
1245.0
1079.0
1200.0
927.0
1259.0
996.0
1155.0
1053.0
1149.0
962.0
1357.0
866.0
1227.0
1049.0
1178.0
908.0
1255.0
979.0
1146.0
1037.0
1155.0
955.0
1353.0
862.0
1220.0
1072.0
1192.0
918.0
1247.0
992.0
1148.0
1047.0
1159.0
941.0
1357.0
855.0
1235.0
1067.0
1191.0
908.0
1249.0
987.0
1139.0
1043.0
1145.0
953.0
1353.0
855.0
1209.0
1066.0
1176.0
913.0
1248.0
962.0
1127.0
1032.0
1151.0
945.0
1344.0
846.0
1220.0
1066.0
1181.0
912.0
1246.0
989.0
1152.0
1039.0
1138.0
956.0
1352.0
859.0
1221.0
1051.0
1174.0
911.0
1257.0
979.0
1145.0
1040.0
1158.0
949.0
1348.0
858.0
1220.0
1075.0
1186.0
916.0
1247.0
989.0
1151.0
1052.0
1159.0
946.0
1359.0
859.0
1239.0
1070.0
1199.0
912.0
1258.0
990.0
1142.0
1048.0
1153.0
961.0
1358.0
861.0
1212.0
1064.0
1183.0
917.0
1265.0
972.0
1143.0
1044.0
1166.0
957.0
1362.0
865.0
1230.0
1083.0
1198.0
925.0
1265.0
1004.0
1169.0
1060.0
1172.0
958.0
1372.0
870.0
1253.0
1081.0
1201.0
924.0
1259.0
1000.0
1151.0
1061.0
1150.0
963.0
1358.0
866.0
1229.0
1057.0
1182.0
912.0
1257.0
978.0
1143.0
1038.0
1157.0
952.0
1343.0
852.0
1212.0
1066.0
1186.0
909.0
1248.0
985.0
1145.0
1044.0
1143.0
943.0
1349.0
853.0
1229.0
1049.0
1176.0
901.0
1246.0
980.0
1139.0
1031.0
1140.0
947.0
1339.0
845.0
1207.0
1060.0
1173.0
904.0
1226.0
976.0
1128.0
1034.0
1136.0
930.0
1334.0
845.0
1218.0
1047.0
1173.0
894.0
1237.0
971.0
1133.0
1023.0
1137.0
941.0
1332.0
840.0
1201.0
1056.0
1172.0
903.0
1224.0
974.0
1130.0
1035.0
1134.0
932.0
1339.0
849.0
1220.0
1041.0
1170.0
898.0
1240.0
972.0
1135.0
1023.0
1140.0
945.0
1330.0
847.0
1201.0
1056.0
1170.0
901.0
1226.0
975.0
1130.0
1033.0
1127.0
932.0
1332.0
846.0
1217.0
1038.0
1163.0
896.0
1238.0
964.0
1131.0
1022.0
1140.0
938.0
1333.0
844.0
1206.0
1058.0
1174.0
901.0
1237.0
978.0
1138.0
1041.0
1128.0
946.0
1345.0
855.0
1228.0
1046.0
1172.0
905.0
1252.0
976.0
1145.0
1028.0
1145.0
947.0
1340.0
853.0
1208.0
1062.0
1173.0
909.0
1231.0
979.0
1135.0
1037.0
1137.0
931.0
1336.0
849.0
1220.0
1047.0
1170.0
896.0
1239.0
971.0
1136.0
1027.0
1131.0
940.0
1328.0
844.0
1201.0
1055.0
1175.0
904.0
1227.0
970.0
1128.0
1031.0
1129.0
935.0
1335.0
845.0
1212.0
1034.0
1159.0
894.0
1237.0
965.0
1127.0
1013.0
1131.0
934.0
1322.0
841.0
1194.0
1045.0
1151.0
891.0
1221.0
972.0
1120.0
1023.0
1108.0
930.0
1318.0
840.0
1177.0
1032.0
1143.0
886.0
1209.0
936.0
1102.0
1006.0
1120.0
906.0
1306.0
828.0
1199.0
1032.0
1152.0
883.0
1219.0
951.0
1115.0
1008.0
1126.0
925.0
1310.0
831.0
1185.0
1039.0
1141.0
891.0
1207.0
959.0
1107.0
1013.0
1111.0
928.0
1310.0
828.0
1166.0
1029.0
1138.0
884.0
1194.0
939.0
1093.0
1002.0
1093.0
903.0
1293.0
822.0
1170.0
1003.0
1125.0
872.0
1203.0
923.0
1087.0
995.0
1108.0
899.0
1295.0
819.0
1185.0
1016.0
1140.0
874.0
1209.0
945.0
1107.0
1002.0
1117.0
919.0
1301.0
826.0
1179.0
1032.0
1136.0
881.0
1201.0
952.0
1095.0
1004.0
1102.0
922.0
1301.0
818.0
1168.0
1027.0
1139.0
874.0
1193.0
953.0
1097.0
1007.0
1089.0
916.0
1293.0
822.0
1154.0
1016.0
1126.0
872.0
1184.0
927.0
1086.0
992.0
1086.0
895.0
1284.0
818.0
1159.0
1002.0
1119.0
868.0
193.0
1916.0
1080.0
987.0
1098.0
893.0
1281.0
812.0
1164.0
997.0
1119.0
865.0
1200.0
919.0
1077.0
987.0
1106.0
894.0
1284.0
816.0
1170.0
1009.0
1127.0
867.0
1203.0
935.0
1091.0
988.0
1103.0
907.0
1297.0
813.0
1173.0
1017.0
1127.0
867.0
1192.0
936.0
1092.0
984.0
1091.0
904.0
1278.0
814.0
1161.0
1016.0
1119.0
867.0
1185.0
940.0
1082.0
991.0
1090.0
905.0
1276.0
811.0
1154.0
1019.0
1123.0
866.0
1182.0
940.0
1084.0
995.0
1092.0
913.0
1285.0
805.0
1152.0
1012.0
1124.0
862.0
1178.0
937.0
1084.0
991.0
1076.0
906.0
1283.0
809.0
1140.0
1004.0
1113.0
860.0
1163.0
930.0
1077.0
983.0
1068.0
897.0
1269.0
806.0
1134.0
1002.0
1111.0
857.0
1158.0
926.0
1075.0
985.0
1066.0
896.0
1268.0
805.0
1134.0
1003.0
1108.0
857.0
1155.0
925.0
1072.0
982.0
1065.0
895.0
1264.0
798.0
1132.0
1002.0
1108.0
859.0
1157.0
925.0
1070.0
979.0
1068.0
895.0
1268.0
801.0
1129.0
1003.0
1108.0
854.0
1160.0
925.0
1072.0
974.0
1066.0
893.0
1269.0
800.0
1134.0
1003.0
1109.0
851.0
1163.0
930.0
1076.0
980.0
1069.0
895.0
1268.0
793.0
1138.0
1000.0
1109.0
851.0
1160.0
926.0
1067.0
975.0
1067.0
893.0
1263.0
789.0
1130.0
994.0
1104.0
850.0
1163.0
926.0
1064.0
977.0
1072.0
897.0
1266.0
796.0
1134.0
1000.0
1105.0
851.0
1167.0
929.0
1065.0
982.0
1074.0
901.0
1272.0
799.0
1143.0
1004.0
1109.0
857.0
1170.0
933.0
1079.0
986.0
1082.0
903.0
1276.0
804.0
1147.0
1010.0
1116.0
856.0
1171.0
931.0
1075.0
985.0
1074.0
901.0
1270.0
798.0
1139.0
1003.0
1115.0
852.0
1166.0
925.0
1071.0
978.0
1070.0
897.0
1266.0
795.0
1132.0
998.0
1107.0
849.0
1164.0
922.0
1068.0
971.0
1068.0
898.0
1265.0
792.0
1133.0
995.0
1104.0
848.0
1166.0
932.0
1072.0
980.0
1073.0
897.0
1265.0
796.0
1140.0
1005.0
1109.0
852.0
1167.0
931.0
1074.0
984.0
1077.0
901.0
1268.0
796.0
1136.0
1006.0
1112.0
851.0
1172.0
929.0
1072.0
980.0
1078.0
904.0
1269.0
797.0
1139.0
1004.0
1113.0
855.0
1170.0
930.0
1073.0
979.0
1079.0
901.0
1276.0
798.0
1138.0
1001.0
1110.0
852.0
1168.0
933.0
1077.0
984.0
1072.0
898.0
1272.0
798.0
1152.0
989.0
1108.0
848.0
1162.0
925.0
1071.0
973.0
1067.0
893.0
1260.0
790.0
1131.0
993.0
1102.0
843.0
1160.0
917.0
1058.0
973.0
1068.0
893.0
1255.0
790.0
1131.0
993.0
1091.0
850.0
1159.0
917.0
1056.0
966.0
1067.0
890.0
1251.0
796.0
1130.0
990.0
1088.0
843.0
1158.0
912.0
1058.0
962.0
1065.0
881.0
1245.0
795.0
1137.0
989.0
1098.0
839.0
1161.0
911.0
1063.0
961.0
1072.0
881.0
1255.0
787.0
1142.0
988.0
1106.0
844.0
1167.0
911.0
1063.0
967.0
1082.0
886.0
1256.0
793.0
1148.0
990.0
1108.0
850.0
1175.0
916.0
1067.0
974.0
1088.0
891.0
1266.0
800.0
1155.0
993.0
1112.0
853.0
1183.0
925.0
1075.0
977.0
1091.0
895.0
1273.0
806.0
1163.0
1001.0
1117.0
855.0
1181.0
924.0
1080.0
977.0
1092.0
894.0
1275.0
801.0
1157.0
1004.0
1116.0
851.0
1176.0
922.0
1075.0
976.0
1088.0
889.0
1268.0
801.0
1159.0
991.0
1117.0
849.0
1172.0
919.0
1073.0
970.0
1086.0
892.0
1270.0
800.0
1149.0
999.0
1114.0
852.0
1177.0
919.0
1074.0
968.0
1080.0
890.0
1265.0
802.0
1147.0
998.0
1110.0
847.0
1171.0
919.0
1070.0
967.0
1078.0
882.0
1263.0
793.0
1146.0
995.0
1107.0
843.0
1173.0
912.0
1066.0
966.0
1078.0
884.0
1255.0
790.0
1146.0
988.0
1104.0
846.0
1169.0
912.0
1064.0
970.0
1082.0
888.0
1255.0
795.0
1147.0
988.0
1105.0
847.0
1175.0
915.0
1063.0
972.0
1084.0
886.0
1260.0
800.0
1152.0
989.0
1102.0
851.0
1176.0
915.0
1060.0
973.0
1086.0
881.0
1266.0
799.0
1157.0
992.0
1101.0
852.0
1178.0
914.0
1063.0
971.0
1088.0
878.0
1260.0
799.0
1157.0
986.0
1099.0
855.0
1178.0
906.0
1064.0
974.0
1088.0
882.0
1264.0
803.0
1159.0
987.0
1110.0
857.0
1187.0
912.0
1067.0
978.0
1091.0
885.0
1270.0
806.0
1165.0
989.0
1108.0
862.0
1189.0
921.0
1074.0
981.0
1097.0
893.0
1277.0
811.0
1169.0
1004.0
1122.0
863.0
1192.0
930.0
1087.0
986.0
1101.0
900.0
1281.0
809.0
1167.0
1011.0
1130.0
859.0
1187.0
931.0
1090.0
984.0
1100.0
904.0
1277.0
813.0
1160.0
1013.0
1119.0
869.0
1184.0
933.0
1076.0
985.0
1088.0
901.0
1275.0
809.0
1146.0
1006.0
1106.0
860.0
1175.0
928.0
1068.0
977.0
1078.0
898.0
266.0
1808.0
1142.0
1000.0
1101.0
852.0
1168.0
927.0
1063.0
976.0
1071.0
886.0
1255.0
799.0
1133.0
998.0
1090.0
846.0
1156.0
915.0
1061.0
968.0
1071.0
885.0
1251.0
793.0
1135.0
989.0
1100.0
843.0
1160.0
909.0
1059.0
961.0
1073.0
889.0
1343.0
907.0
1404.0
1342.0
1651.0
1413.0
2251.0
2158.0
3352.0
5662.0

Render Unfiltered Data


In [17]:
plt.figure(figsize=(10.5, 8), dpi=300)
plt.plot(x_axis, y_axis, linewidth=.25)
plt.title('unfiltered encoder events')
plt.xlabel("time (s)")
plt.ylabel("velocity (mm/s)")
plt.show()


Typical Signal


In [51]:
scope_x_tick = 80
left_x = -1960
x_events = [920, 760, 870, 780]
plt.figure(figsize=(10.5, 8), dpi=300)
img = plt.imread("encoder.png")
plt.imshow(img, extent=(-9 * 400,9 * 400,-800,800))
plt.title('Typical Signal')
plt.axvline(x=left_x, color="cyan", linestyle="dashed")
plt.axvline(x=left_x + x_events[0], color="yellow", linestyle="dashed")
plt.axvline(x=left_x + x_events[0] + x_events[1], color="cyan", linestyle="dashed")
plt.axvline(x=left_x + x_events[0] + x_events[1] + x_events[2], color="yellow", linestyle="dashed")
plt.axvline(x=left_x + x_events[0] + x_events[1] + x_events[2] + x_events[3], color="cyan", linestyle="dashed")
plt.xlabel(u"µ seconds")
plt.show()


Setup Taps


In [3]:
# Taps
a = .50 / 4.00
b = .375 / 4.00
c = .125 / 4.00
taps = [
    a,
    a,
    a,
    a,
    b,
    b,
    b,
    b,
    c,
    c,
    c,
    c,
]

print "taps sum={}".format(sum(taps))

# +--[ Render Taps ]--------------------------------------------------------------#

with plt.xkcd():
    plt.figure(figsize=(10.5, 3.5), dpi=300)
    plt.plot(range(0,len(taps)), taps)
    plt.title('Tap Values')
    plt.xticks(range(0,len(taps)))
    plt.xlabel("tap number")
    plt.ylabel("multiplier")
    plt.show()


taps sum=1.0

Filter


In [4]:
# Value provider for taps
z = lambda i, data: 0 if i < 0 else data[i]

def ffir(i, data) :
    '''
    len(taps) tap FIR filter
    '''
    return sum([taps[ti] * z(i-ti, data) for ti in range(0, len(taps))])

Render Filtered Data


In [54]:
filterd_y = [ ffir(i, y_axis) for i in range(0, len(y_axis)) ]

plt.figure(figsize=(10.5, 8), dpi=300)
plt.plot(x_axis, filterd_y, linewidth=.25)
plt.title('filtered encoder events')
plt.xlabel("time (s)")
plt.ylabel("velocity (mm/s)")
plt.show()


Integration of Filtered Data


In [60]:
print "{:.2f} cm".format(np.trapz(filterd_y, x_axis)/10.0)


10.21 cm